﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace FileUpload
{
    public partial class 为gridview每行添加超链接 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void RowDataBind(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dr = e.Row.DataItem as DataRowView;
                //string tourl = dr["CARTONNO"].ConvertObjToStr();
                Label lbLink = e.Row.FindControl("lbLink") as Label;

                lbLink.Text = "<a href='#'>aaa</a>";

                string sql = "select classDesc from Class1";
                SqlParameter[] ps={};
                DataTable dt = DBAccess.ExecuteDataTable(sql);
                DropDownList ddl = e.Row.FindControl("ddl") as DropDownList;
                BindDDL(sql,ps,ddl,"classDesc","classDesc");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="ps">参数列表</param>
        /// <param name="ddl">要绑定的下拉列表</param>
        /// <param name="textField">显示文本</param>
        /// <param name="valueField">显示文本对应的值</param>
        private void BindDDL(string sql,SqlParameter[] ps,DropDownList ddl,string textField,string valueField)
        {
            DataTable dt = new DataTable();
            if (ps != null)
            {
                dt = DBAccess.ExecuteDataTable(sql, ps);
            }
            else
            {
                dt = DBAccess.ExecuteDataTable(sql);
            }
            
            ddl.DataSource = dt;
            ddl.DataTextField = textField;
            ddl.DataValueField = valueField;
            ddl.DataBind();
        }
    }
}